package edu.buaa.act.travel.m.model;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import edu.buaa.act.travel.m.Constants;
import edu.buaa.act.travel.m.data.TripSimp;
import edu.buaa.act.travel.m.utils.JSONParser;

public class TripModel {
	
	private List<TripSimp> mTripList;
	
	public TripModel(final String result) {
		mTripList = new ArrayList<TripSimp>();
		
		final JSONObject jo = JSONParser.getJSONObject(result);
		final JSONArray ja = JSONParser.getJSONArray(jo, Constants.KEY_TRIPS);
		final int size = ja.length();
		for(int i = 0; i < size; i++) {
			final JSONObject item = JSONParser.getJSONObject(ja, i);
			mTripList.add(new TripSimp(JSONParser.getString(item, Constants.KEY_TRIP_ID), 
					JSONParser.getString(item, Constants.KEY_TRIP_NAME)));
		}
	}

	public List<TripSimp> getTrips() {
		return mTripList;
	}
}
